home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / blankery / bserverdir / sources / clients / clock.c < prev    next >
C/C++ Source or Header  |  1994-11-29  |  4KB  |  162 lines

  1. ;/*
  2. sc Clock.c DATA=FAR NMINC STRMERGE NOSTKCHK IGNORE=73 IGNORE=94 STRUCTUREEQUIVALENCE NOSTDIO
  3. slink from LIB:c.o Clock.o to //Clients/Clock LIB LIB:sc.lib LIB:amiga.lib /lib/client.lib SC SD NOICONS STRIPDEBUG
  4. delete Clock.o
  5. quit
  6.  
  7.  Clock 1.2  (Client for BServer)
  8.  
  9.  Copyright © 1994 by Stefano Reksten of 3AM - The Three Amigos!!!
  10.  All rights reserved.
  11. */
  12.  
  13. #include <exec/types.h>
  14. #include <exec/memory.h>
  15. #include <graphics/text.h>
  16. #include <graphics/rastport.h>
  17. #include <time.h>
  18.  
  19. #include <clib/alib_protos.h>
  20. #include <clib/exec_protos.h>
  21. #include <clib/intuition_protos.h>
  22. #include <clib/graphics_protos.h>
  23. #include <clib/utility_protos.h>
  24. #include <clib/diskfont_protos.h>
  25. #include <clib/icon_protos.h>
  26.  
  27. #include "/include/client.h"
  28. #include "/include/client_pragmas.h"
  29.  
  30. struct IntuitionBase *IntuitionBase;
  31. struct GfxBase *GfxBase;
  32. struct Library *UtilityBase, *IconBase, *DiskfontBase;
  33. struct DisplayIDInformation *dinfo;
  34.  
  35. struct TextAttr tattr = { "topaz.font", 8, 0, FPF_DISKFONT };
  36. struct TextFont *newfont;
  37.  
  38. char clkstring[5] = { ' ','0',':','0','0' };
  39. struct IntuiText itext = { 1, 0, JAM1, 0, 0, NULL, clkstring, NULL };
  40.  
  41. extern ULONG RangeSeed;
  42.  
  43. void DrawClock( void )
  44. {
  45. struct Screen *scr;
  46. UWORD swidth, sheight, xcrd, ycrd;
  47. struct Rectangle *rect;
  48. ULONG secs, mics, ticks, drawn = 0;
  49. struct ClockData clock;
  50. UWORD fontheight;
  51.  
  52. rect = GETTXTOSCANRECT(dinfo);
  53.  
  54. swidth = RECTANGLEWIDTH(rect);
  55. sheight = RECTANGLEHEIGHT(rect);
  56.  
  57. if ( scr = OpenScreenTags( NULL,
  58.     SA_DisplayID, DISPLAYID( dinfo ),
  59.     SA_Width, swidth,
  60.     SA_Height, sheight,
  61.     SA_Left, (RECTANGLEWIDTH(rect) - swidth)/2,
  62.     SA_Top, 0,
  63.     SA_Depth, 1,
  64.     SA_Overscan, OSCAN_TEXT,
  65.     SA_Type, CUSTOMSCREEN,
  66.     SA_Quiet, TRUE,
  67.     TAG_END ) )
  68.     {
  69.     register struct ViewPort *vp = &(scr->ViewPort);
  70.     register struct RastPort *rp = &(scr->RastPort);
  71.  
  72.     SpritesOff();
  73.  
  74.     SetRGB4( vp, 0, 0, 0, 0 );
  75.     SetRGB4( vp, 1, 5, 10, 15 );
  76.  
  77.     fontheight = ( newfont ? newfont->tf_YSize : rp->Font->tf_YSize );
  78.  
  79.     ticks = 200;
  80.     while( STILL_BLANKING )
  81.         {
  82.         WaitTOF();
  83.  
  84.         if ( ticks++ == 200 )
  85.             {
  86.             ticks = 0;
  87.             if ( drawn++ )
  88.                 {
  89.                 itext.FrontPen = 0;
  90.                 PrintIText( rp, &itext, xcrd, ycrd );
  91.                 }
  92.             CurrentTime( &secs, &mics );
  93.             Amiga2Date( secs, &clock );
  94.             clkstring[0] = ( clock.hour > 10 ? '0' + clock.hour / 10 : ' ' );
  95.             clkstring[1] = '0' + clock.hour % 10;
  96.             clkstring[3] = '0' + clock.min / 10;
  97.             clkstring[4] = '0' + clock.min % 10;
  98.             itext.FrontPen = 1;
  99.             xcrd = RangeRand( swidth - IntuiTextLength( &itext ));
  100.             ycrd = RangeRand( sheight - fontheight );
  101.             PrintIText( rp, &itext, xcrd, ycrd );
  102.             }
  103.         }
  104.  
  105.     CloseScreen( scr );
  106.     SpritesOn();
  107.     }
  108. else
  109.     SendClientMsg( ACTION_FAILED );
  110. }
  111.  
  112.  
  113. void __main( char *line )
  114. {
  115. if ( IntuitionBase = (struct IntuitionBase *)OpenLibrary( "intuition.library", 37L ) )
  116.     {
  117.     if ( GfxBase = (struct GfxBase *)OpenLibrary( "graphics.library", 37L ) )
  118.         {
  119.         if ( UtilityBase = OpenLibrary( "utility.library", 37L ) )
  120.             {
  121.             if ( IconBase = OpenLibrary( "icon.library", 37L ) )
  122.                 {
  123.                 struct DiskObject *obj;
  124.  
  125.                 if ( obj = GetDiskObject( "Clock" ) )
  126.                     {
  127.                     char **tooltypes = obj->do_ToolTypes;
  128.                     tattr.ta_YSize = ArgInt( tooltypes, "FONTHEIGHT", 8 );
  129.                     tattr.ta_Name = ArgString( tooltypes, "FONTNAME", "topaz.font" );
  130.  
  131.                     if ( DiskfontBase = OpenLibrary( "diskfont.library", 37L ) )
  132.                         {
  133.                         if ( newfont = OpenDiskFont( &tattr ) )
  134.                             {
  135.                             tattr.ta_Flags = newfont->tf_Flags;
  136.                             itext.ITextFont = &tattr;
  137.                             }
  138.  
  139.                         if ( dinfo = OpenCommunication() )
  140.                             {
  141.                             RangeSeed = time( NULL );
  142.                             DrawClock();
  143.                             CloseCommunication( dinfo );
  144.                             }
  145.  
  146.                         if ( newfont )
  147.                             CloseFont( newfont );
  148.  
  149.                         CloseLibrary( DiskfontBase );
  150.                         }
  151.                     FreeDiskObject( obj );
  152.                     }
  153.                 CloseLibrary( IconBase );
  154.                 }
  155.             CloseLibrary( UtilityBase );
  156.             }
  157.         CloseLibrary( (struct Library *)GfxBase );
  158.         }
  159.     CloseLibrary( (struct Library *)IntuitionBase );
  160.     }
  161. }
  162.